﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronCommander.ViewModels;

namespace IronCommander.Utils
{
    class FileSortingComparer : Comparer<FileViewModel>
    {
        int FirstNonDefault(params Func<int>[] values)
        {
            return values.Select(v => v()).FirstOrDefault(v => v != 0);
        }

        public override int Compare(FileViewModel x, FileViewModel y)
        {
            return FirstNonDefault(
                () => -x.IsParentPath.CompareTo(y.IsParentPath),
                () => -x.IsFolder.CompareTo(y.IsFolder),
                () => x.FullName.CompareTo(y.FullName));
        }
    }

}
